<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\AbductionContact;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use App\Models\AbductionContact as AbductionContactModel;

class AbductionContactController extends AdminController
{
    protected $title = '联系我们';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $feedback_types = [
            1 => '评论',
            2 => '建议',
            3 => '错误',
        ];
        return Grid::make(AbductionContact::with('member'), function (Grid $grid) use ($feedback_types){
            $grid->column('contact_id','ID')->sortable();
            $grid->column('feedback_type','反馈类型')->display(function($feedback_type) use ($feedback_types) {
                return $feedback_types[$feedback_type];
            });
            $grid->column('contact_name');
            $grid->column('contact_email');
//            $grid->column('contact_content');
//            $grid->column('mailbox_address');
            $grid->column('member.member_name','提交人');
            $grid->column('feedback_time');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('contact_id');

            });
        });
    }


    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        $feedback_types = [
            1 => '评论',
            2 => '建议',
            3 => '错误',
        ];
        $model = AbductionContact::with('member');
        return Show::make($id, $model, function (Show $show) use ($feedback_types) {
//            $show->field('contact_id');
            $show->field('feedback_type','反馈类型')->as(function ($type) use ($feedback_types){
                return $feedback_types[$type];
            });
            $show->field('contact_name');
            $show->field('contact_email');
            $show->field('contact_content');
            $show->field('mailbox_address');
            $show->field('member.member_name','提交人姓名');
            $show->field('feedback_time');
            $show->disableDeleteButton();
            $show->disableEditButton();
//            $show->disableListButton();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new AbductionContact(), function (Form $form) {
            $form->display('contact_id');
            $form->text('feedback_type');
            $form->text('contact_name');
            $form->text('contact_email');
            $form->text('contact_content');
            $form->text('mailbox_address');
            $form->text('member_id');
            $form->text('feedback_time');
        });
    }
}
